package com.example.demo.controller;

import com.example.demo.Response;
import com.example.demo.dto.ScheduleDTO;
import com.example.demo.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Set;

@RestController
public class ScheduleController {
    @Autowired
    private ScheduleService scheduleService;

    @GetMapping("/schedule/{userId}")
    public Response<Set<ScheduleDTO>> getScheduleByUserId(@PathVariable long userId) {
        return Response.newSuccess(scheduleService.getScheduleByUserId(userId));
    }

    @GetMapping("/schedule/{userId}/date/{date}")
    public Response<Set<ScheduleDTO>> getScheduleByUserIdAndDate(@PathVariable long userId, @PathVariable String date) {
        return Response.newSuccess(scheduleService.getScheduleByUserIdAndDate(userId, date));
    }

    @GetMapping("/schedule/{userId}/date/{date}/dateId/{dateId}")
    public Response<ScheduleDTO> getScheduleByUserIdAndDateAndDateId(@PathVariable long userId, @PathVariable String date, @PathVariable int dateId) {
        return Response.newSuccess(scheduleService.getScheduleByUserIdAndDateAndDateId(userId, date, dateId));
    }

    @PostMapping("schedule/{userId}/outfitName/{outfitName}")
    public Response<Long> addScheduleByUserIdAndName(@RequestBody ScheduleDTO scheduleDTO, @PathVariable long userId, @PathVariable String outfitName) {
        return Response.newSuccess(scheduleService.addScheduleByUserIdAndName(scheduleDTO, userId, outfitName));
    }

    @PostMapping("/schedule/{Id}/aiSuggestion/")
    public Response<Long> addAiSuggestionToScheduleById(@PathVariable long Id, @RequestBody String aiSuggestion) {
        return Response.newSuccess(scheduleService.addAiSuggestionToScheduleById(Id, aiSuggestion));
    }

    @DeleteMapping("/schedule/{userId}/date/{date}")
    public void deleteScheduleByUserIdAndDate(@PathVariable long userId, @PathVariable String date) {
        scheduleService.deleteScheduleByUserIdAndDate(userId, date);
    }

    @PutMapping("/schedule/{userId}/date/{date}/dateId/{dateId}")
    public Response<ScheduleDTO> updateScheduleByUserIdAndDateAndDateId(@PathVariable long userId, @PathVariable String date, @RequestParam String content, @RequestParam String aiSuggestion, @PathVariable int dateId) {
        return Response.newSuccess(scheduleService.updateScheduleByUserIdAndDateAndDateId(userId, date, content, aiSuggestion, dateId));
    }

    @DeleteMapping("/schedule/{userId}/date/{date}/dateId/{dateId}")
    public Response<Void> deleteScheduleByUserIdAndDateAndDateId(@PathVariable long userId, @PathVariable String date, @PathVariable int dateId) {
        scheduleService.deleteScheduleByUserIdAndDateAndDateId(userId, date, dateId);
        return Response.newSuccess(null);
    }
}
